<?php

use Faker\Generator as Faker;
use App\Models\Company;

$factory->define(App\Models\Filiale::class, function (Faker $faker) {
    $sentence = $faker->sentence();
    $remark = $faker->sentence();
    // 随机取一个月以内的时间
    $updated_at = $faker->dateTimeThisMonth();
    // 传参为生成最大时间不超过，创建时间永远比更改时间要早
    $created_at = $faker->dateTimeThisMonth($updated_at);

    $addresses = [
        ["广东省", "汕头市", "金平区"],
        ["广东省", "汕头市", "龙湖区"],
        ["广东省", "汕头市", "澄海区"],
        ["广东省", "汕头市", "潮阳区"],
        ["广东省", "汕头市", "潮南区"],
        ["广东省", "汕头市", "南澳县"],
        ["广东省", "深圳市", "福田区"],
    ];
    $address  = $faker->randomElement($addresses);
    $company = Company::all()->random();
    $phoneNumber=$faker->phoneNumber;

    return [
        'name' => $company->name.'分店',
        'company_id' => $company->id,
        'phone'             => $phoneNumber,
        'address'           => $address[0].$address[1].$address[2].sprintf('第%d街道第%d号', $faker->randomNumber(2), $faker->randomNumber(3)),
        'created_at' => $created_at,
        'updated_at' => $updated_at,
    ];
});
